import cv2
import numpy as np

if __name__ == '__main__':
    # 获取摄像头
    cap = cv2.VideoCapture(0)

    #循环读取摄像头
    while True:
        ret,frame = cap.read()
        if ret:
            # 显示图像
            cv2.imshow('frame', frame)
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
    #释放摄像头
    cap.release()
    cv2.destroyAllWindows()
    # 退出程序
    exit(0)